<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="来源ID" prop="sourceId">-->
<!--        <el-input-->
<!--          v-model="queryParams.sourceId"-->
<!--          placeholder="请输入来源ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="所属平台" prop="terid">
        <el-input
          v-model="queryParams.terid"
          placeholder="请输入所属平台"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属机构" prop="mecid">
        <el-input
          v-model="queryParams.mecid"
          placeholder="请输入所属机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备序列号" prop="eid">
        <el-input
          v-model="queryParams.eid"
          placeholder="请输入设备序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="床位号" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入床位号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入患者姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入患者年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="pressureList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="来源ID" align="center" prop="sourceId" />-->
      <el-table-column label="所属平台" align="center" prop="terid" />
      <el-table-column label="所属机构" align="center" prop="mecid" />
      <el-table-column label="设备序列号" align="center" prop="eid" />
      <el-table-column label="床位号" align="center" prop="uid" />
      <el-table-column label="患者姓名" align="center" prop="name" />
      <el-table-column label="患者年龄" align="center" prop="age" />

      <el-table-column label="用户性别" align="center" prop="sex">
        <template slot-scope="scope">
          <div>{{scope.row.sex === '1' ? '男' : scope.row.sex === '2' ? '女' : ''}}</div>
        </template>
      </el-table-column>

      <el-table-column label="收缩压" align="center" prop="shrink" />
      <el-table-column label="舒张压" align="center" prop="diastole" />
      <el-table-column label="脉率" align="center" prop="heartRate" />
      <el-table-column label="血压采集时间" align="center" prop="takeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.takeTime)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="结论" align="center" prop="result" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['qiushi:deviceData:qiushidevicebloodpressure:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['qiushi:deviceData:qiushidevicebloodpressure:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改血压设备数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="来源ID" prop="sourceId">
          <el-input v-model="form.sourceId" placeholder="请输入来源ID" />
        </el-form-item>
        <el-form-item label="所属平台" prop="terid">
          <el-input v-model="form.terid" placeholder="请输入所属平台" />
        </el-form-item>
        <el-form-item label="所属机构" prop="mecid">
          <el-input v-model="form.mecid" placeholder="请输入所属机构" />
        </el-form-item>
        <el-form-item label="设备序列号" prop="eid">
          <el-input v-model="form.eid" placeholder="请输入设备序列号" />
        </el-form-item>
        <el-form-item label="床位号" prop="uid">
          <el-input v-model="form.uid" placeholder="请输入床位号" />
        </el-form-item>
        <el-form-item label="患者姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入患者姓名" />
        </el-form-item>
        <el-form-item label="患者年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入患者年龄" />
        </el-form-item>
        <el-form-item label="收缩压" prop="shrink">
          <el-input v-model="form.shrink" placeholder="请输入收缩压" />
        </el-form-item>
        <el-form-item label="舒张压" prop="diastole">
          <el-input v-model="form.diastole" placeholder="请输入舒张压" />
        </el-form-item>
        <el-form-item label="脉率" prop="heartRate">
          <el-input v-model="form.heartRate" placeholder="请输入脉率" />
        </el-form-item>
        <el-form-item label="血压采集时间" prop="takeTime">
          <el-date-picker clearable
                          v-model="form.takeTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择血压采集时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结论" prop="result">
          <el-input v-model="form.result" placeholder="请输入结论" />
        </el-form-item>
        <el-form-item label="0正常 1删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入0正常 1删除" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPressure, getPressure, delPressure, addPressure, updatePressure } from "@/api/qiushi/deviceData/qiushidevicebloodpressure";

export default {
  name: "Qiushidevicebloodpressure",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 血压设备数据表格数据
      pressureList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sourceId: null,
        terid: null,
        mecid: null,
        eid: null,
        uid: null,
        name: null,
        age: null,
        sex: null,
        shrink: null,
        diastole: null,
        heartRate: null,
        takeTime: null,
        result: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        terid: [
          { required: true, message: "所属平台不能为空", trigger: "blur" }
        ],
        mecid: [
          { required: true, message: "所属机构不能为空", trigger: "blur" }
        ],
        eid: [
          { required: true, message: "设备序列号不能为空", trigger: "blur" }
        ],
        uid: [
          { required: true, message: "床位号不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "患者姓名不能为空", trigger: "blur" }
        ],
        shrink: [
          { required: true, message: "收缩压不能为空", trigger: "blur" }
        ],
        diastole: [
          { required: true, message: "舒张压不能为空", trigger: "blur" }
        ],
        heartRate: [
          { required: true, message: "脉率不能为空", trigger: "blur" }
        ],
        takeTime: [
          { required: true, message: "血压采集时间不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "0正常 1删除不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询血压设备数据列表 */
    getList() {
      this.loading = true;
      listPressure(this.queryParams).then(response => {
        this.pressureList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sourceId: null,
        terid: null,
        mecid: null,
        eid: null,
        uid: null,
        name: null,
        age: null,
        sex: null,
        shrink: null,
        diastole: null,
        heartRate: null,
        takeTime: null,
        result: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加血压设备数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPressure(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改血压设备数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePressure(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPressure(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除血压设备数据编号为"' + ids + '"的数据项？').then(function() {
        return delPressure(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/qiushidevicebloodpressure/export', {
        ...this.queryParams
      }, `pressure_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
